package ru.spb.bragnikita.myevents.ibatis.runners;

import org.apache.ibatis.logging.LogFactory;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import ru.spb.bragnikita.myevents.ibatis.IBatisUtils;
import ru.spb.bragnikita.myevents.ibatis.domain.Author;
import ru.spb.bragnikita.myevents.ibatis.mappers.AuthorMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author Nikita.Brazhnikov
 */
public class GetAuthors {

	private static final Logger logger = Logger.getLogger(GetAuthors.class.getName());

	public static void main(String[] args) {
		final SqlSessionFactory sessionFactory = IBatisUtils.getFactory();
		final SqlSession session = sessionFactory.openSession();
		final AuthorMapper mapper = session.getMapper(AuthorMapper.class);

		Author object = mapper.getAuthor(1);
		System.out.println(object);

		List<Author> objects = mapper.getAuthors();
		System.out.println(objects.getClass().getName());
		System.out.println(objects);
		LogFactory.useLog4JLogging();
		objects = mapper.getAuthorsWithParams("Nikita", "Brazhnikov");
		System.out.println(objects.getClass().getName());
		System.out.println(objects);

		Map<String, String> paramsMap = new HashMap<String, String>();
		paramsMap.put("firstName", "Nikita");
		//paramsMap.put("lastName", "Brazhnikov");
		objects = mapper.getAuthorsWithHashMap(paramsMap);
		System.out.println(objects);

		session.close();
	}
}
